﻿package com.cf.core.control{
	import flash.display.Sprite;
	import flash.events.EventDispatcher;
	import com.cf.core.Utils.*;
	import com.cf.core.model.MouseBase;
	import com.cf.core.events.GameEvent;
	public class BaseGameLevel extends EventDispatcher{
		private var G_parent:*;
		private var G_VAR:cache;
		public function get VAR():Function{return G_VAR.address }
		public function get RELEASE():Function{return G_VAR.RELEASE }
		private var G_Scene:Sprite=new Sprite();
		public function get SCENE():Sprite{return G_Scene}
		//	public function set SCENE(_s:Sprite):void{G_Scene=_s}	// Backdoor.
		private var G_mouse:MouseBase;
		public function get MOUSE():MouseBase{return G_mouse}
		
		
		public function addScene(_Layer:String, _Class:*):void{
			// _Class is this child of com.cf.core.view.MyScene;
			this.VAR(_Layer, _Class);
			this.VAR(_Layer).init();
			this.SCENE.addChild( VAR(_Layer) );
		}//fn
		public function delScene(_Layer:String):void{
			this.SCENE.removeChild( VAR(_Layer) );
			this.RELEASE(_Layer);
		}//fn
		public function changeScene(_Layer:String, _Class:*):void{
			// _Class is this child of com.cf.core.view.MyScene;
			this.delScene(_Layer);
			this.addScene(_Layer, _Class);
		}//fn
		//
		// Base Function
		//
		public function BaseGameLevel():void{
			before_init();
		}//fn
		private function before_init():void{
			G_VAR = new cache();	// USAGE: BaseGameLevel.VAR.address('xxx', CLASS);
			G_Scene = new Sprite();
			G_Scene.name = "Scene_"+G_Scene.name;
			G_mouse = new MouseBase();
		}//fn
		public function init(_p:*=null):void{
			trace("BaseGameLevel : init");
			if(_p!=null)G_parent=_p;
			G_mouse.ASSIGN=G_parent;
		}//fn
		
		//
		// EVENT
		//
		public function START():void{
			trace("BaseGameLevel : GameStart");
			dispatchEvent(new GameEvent(GameEvent.START) );
		}//fn
		public function PAUSE():void{
			trace("BaseGameLevel : GamePause");
			dispatchEvent(new GameEvent(GameEvent.PAUSE));
		}//fn
		public function RESUME():void{
			trace("BaseGameLevel : GameResume");
			dispatchEvent(new GameEvent(GameEvent.RESUME));
		}//fn
		public function FAIL():void{
			trace("BaseGameLevel : GameFAIL");
			dispatchEvent(new GameEvent(GameEvent.FAIL));
		}//fn
		public function END():void{
			trace("BaseGameLevel : GameOther");
			dispatchEvent(new GameEvent(GameEvent.OTHER, {VAR:"init"}));
		}//fn
	}//class
}//package